package com.clstu.regexp;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 作业3
 */
public class Homework03 {
    public static void main(String[] args) {
        //解析url,得到协议,域名,端口号,文件名
        String content = "https://www.bilibili.com:9999/video/BV1fh411y7R8/?p=903&spm_id_from=pageDriver&vd_source=075000c5f1595802475a44f77a45fdd7abc.doc";
                  //                                                                         这里的/必须要有,因为有文件的话必然前面会有/,所有不能用/*来写正则表达式
        String regStr = "^(http|https)://([\\w-\\.]+[a-zA-Z]):*(\\d+)*(/[\\w!?@#$%^&*()_=+\\-]+)*/([\\w-!@#$%^&*()_?+=]+\\.[a-zA-Z]+)*$";
        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);
        if (matcher.find()){
            System.out.println("协议:"+matcher.group(1));
            System.out.println("域名:"+matcher.group(2));
            System.out.println("端口号:"+matcher.group(3));
            System.out.println("文件名:"+matcher.group(5));
        }
    }
}
